<?php


namespace App\Utils\Upload;


use App\Task\MongoTask;
use Hyperf\HttpMessage\Upload\UploadedFile;
use MongoDB\GridFS\Bucket;

class Server
{
    /**
     * @param UploadedFile $file
     * @param array $allowOptions
     * @return Upload
     */
    public function upload(UploadedFile $file, $allowOptions = []): Upload
    {
        $upload = make(Upload::class, [$file, $allowOptions]);
        $upload->validated();
        return $upload->store();
    }

    /**
     * @param string $md5
     * @return View
     */
    public function view(string $md5): View
    {

        $conn = di(MongoTask::class)->manager();//如果设置了密码自己配置DSN
        $grid = new Bucket($conn, 'sy_task');
        return make(View::class, [$grid, $md5]);
    }
}